Ext.define('cp.view.form.EditMedico',{
    extend: 'cp.view.form.MedicoBase',
    alias: 'widget.editMedico',

    initComponent: function(){
        this.callParent(arguments);
  
        var input = Ext.create('Ext.form.field.Text', {
                    name: 'idUsuario',
                    hidden: true
                });
        this.add(input);
        
        // Configuro campos como solo lectura.
        var form = this.getForm();
        form.findField('apellido').readOnly = true;
        form.findField('nombre').readOnly = true;
        form.findField('dni').readOnly = true;
        form.findField('fechaNacimiento').readOnly = true;
        form.findField('matProv').readOnly = true;
        
    },
    populateEspecialidades: function(idUsuario){
        var store = Ext.create('cp.store.form.MedicoEspecialidad',{});
        var me = this;
        store.load({
            params: {idUsuario: idUsuario},
            callback: function(records,option,success){
                var chkArray = [];
                for(var i = 0; i < records.length; i++){
                chkArray.push({name:'especialidades[]', boxLabel:records[i].data.especialidad, 
                    inputValue:records[i].data.idEspecialidad, checked: records[i].data.checked});
                }
                me.renderChkGrp(chkArray,'Especialidades','campos');
            }
        });
    },
    populateObrasSociales: function(idUsuario){
        var store = Ext.create('cp.store.form.MedicoObraSocial',{});
        var me = this;
        store.load({
            params: {idUsuario: idUsuario},
            callback: function(records,option,success){
                var chkArray = [];
                for(var i = 0; i < records.length; i++){
                chkArray.push({name:'obras[]', boxLabel:records[i].data.obra, 
                    inputValue:records[i].data.idObra, checked: records[i].data.checked});
                }
                me.renderChkGrp(chkArray,'Obras sociales','campos');
            }
        });
    },
    populateDiasAtencion: function(idMedico){
       var store = Ext.create('cp.store.form.MedicoDiaAtencion',{});
        
       var me = this;
       store.load({
            params: {idUsuario: idMedico},
            callback: function(records,option,success){
                var chkArray = [];
                for(var i = 0; i < records.length; i++){
                chkArray.push({name:'dias[]', boxLabel:records[i].data.dia, 
                    inputValue:records[i].data.idDia, checked: records[i].data.checked});
                }
                me.renderChkGrp(chkArray,'Dias atención','campos');
            }
        });
    }
});